<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Faq extends API_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('faq_model');
    }

    /**
    * 提问
    */
    public function save_faq()
    {
    	$site_id = $this->input->post('site_id', TRUE);
    	$problem = $this->input->post('problem', TRUE);
    	//$contents = $this->input->post('answer', TRUE);
    	if(!$site_id){ echo "提问出现异常!"; exit;}
    	if(!$problem){echo "请填写问题";exit;}
    	$data = array(
    		'site_id' => $site_id,
    		'problem' => $problem,
    		'create_time' => time(),
    	);
    	$insert_id = $this->faq_model->insert($data);
    	if($insert_id){
    		echo "提问成功,请等待回答!";
    	}else{
    		echo "网络出现异常，请稍后再试!";
    	}
    	exit;
    }

    /**
     * faq列表
     */
	public function get_faqs()
	{
		$site_id = $this->input->post('site_id', TRUE);
		if(!$site_id){
			echo false;
			exit;
		}
		$result = $this->faq_model->get_faq_by_id($site_id);
		if($result) {
			echo json_encode($result);
		}else{
			echo false;
		}
	}
}